package com.iafme.utils;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.mail.MailUtil;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import com.iafme.dto.req.ExamReqDTO;
import com.systemframework.constants.Constants;
import com.systemframework.exception.ResultException;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/4 17:28
 */
public class ExamSignUtils {


    public static String createSign(ExamReqDTO examReqDTO) {
        Map<String, Object> map = MapUtil.newHashMap();
        map.put(Constants.PC_NAME,examReqDTO);
        return JWTUtil.createToken(map, Constants.USER_NAME.getBytes());
    }

    public static ExamReqDTO parseSign(String token) {
        boolean verify = JWTUtil.verify(token, Constants.USER_NAME.getBytes());
        if (!verify) {
            throw new ResultException("签名校验失败");
        }
        final JWT jwt = JWTUtil.parseToken(token);
        Object payload = jwt.getPayload(Constants.PC_NAME);
        return Convert.convert(ExamReqDTO.class,payload);
    }







}
